<template>
  <div class="register">
    <!--浏览器兼容提示-->
    <div class="tip">
      <div class="warn">温馨提示：您当前的浏览器版本过低，请使用其他浏览器</div>
    </div>
    <div class="register-box">
      <section class="header-switch">
        <span
          :class="[infoType=='0'?'active':'']"
          @click="selectUser('0')"
        >企业客户</span>
        <span
          :class="[infoType=='1'?'active':'']"
          @click="selectUser('1')"
        >个人客户</span>
      </section>
      <div class="js-sign-in-container">
        <div
          class="form"
          v-show="infoType=='0'"
        >
          <div class="password public">
            <input
              type="text"
              v-model.trim="companyName"
              placeholder="请输入您的企业名称"
            >
            <i class="iconfont iconqiye"></i>
          </div>
          <div class="password public">
            <input
              type="text"
              v-model.trim="contactName"
              placeholder="请输入您的姓名"
            >
            <i class="iconfont icontubiao211"></i>
          </div>
          <div class="username public">
            <input
              type="text"
              v-model.trim="contactPhone"
              placeholder="请输入手机号"
              maxlength="11"
            >
            <i class="iconfont iconyunongtongqingshurushoujihaoma"></i>
          </div>
          <!-- <div class="public">
            <input
              class="code"
              v-model.trim="code"
              placeholder="请填写短信验证码"
            >
            <i class="iconfont iconcodev"></i>
            <span
              class="getCode"
              :class="[btnValue>=0?'activeColor':'']"
              @click="getCode()"
            >{{btnValue}}</span>
          </div> -->
          <div class="username public">
            <input
              type="text"
              v-model.trim="contactEmail"
              placeholder="请输入邮箱"
            >
            <i class="iconfont iconyouxiang1"></i>
          </div>
          <el-button
            type="success"
            :disabled="!checked"
            @click="submit()"
          >立即注册</el-button>
        </div>
        <div
          class="form"
          v-show="infoType=='1'"
        >
          <div class="password public">
            <input
              type="text"
              v-model.trim="contactName"
              placeholder="请输入您的姓名"
            >
            <i class="iconfont icontubiao211"></i>
          </div>
          <div class="username public">
            <input
              type="text"
              v-model.trim="contactPhone"
              placeholder="请输入手机号"
              maxlength="11"
            >
            <i class="iconfont iconyunongtongqingshurushoujihaoma"></i>
          </div>
          <el-button
            type="success"
            :disabled="!checked"
            @click="submit()"
          >立即注册</el-button>
        </div>
      </div>
      <div class="protocol">
        <el-checkbox v-model="checked">我已阅读并同意</el-checkbox>
        <a href="javascript:void(0)">《启亿HR服务协议》</a>
      </div>
      <div
        class="goback"
        @click="loginJump()"
      >返回登录</div>
    </div>
  </div>
</template>
<script>
import base from "@/assets/js/base";
import { requestApiPost } from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
export default {
  name: "register",
  data() {
    return {
      checked: true,
      contactName: "",
      contactPhone: "",
      contactEmail: "",
      companyName: "",
      password: "",
      infoType: "0",
      code: "",
      newCode: "",
      btnValue: "获取"
    };
  },
  methods: {
    //注册
    submit() {
      if (this.infoType == "0") {
        if (
          !this.contactName ||
          !this.contactPhone ||
          !this.companyName ||
          !this.contactEmail
        ) {
          this.$message.warning("信息不完整");
          return;
        }
      } else {
        if (!this.contactName || !this.contactPhone) {
          this.$message.warning("信息不完整");
          return;
        }
      }
      var reqData = {
        companyName: this.infoType == 0 ? this.companyName : this.contactName,
        contactPhone: this.contactPhone,
        contactName: this.contactName,
        contactEmail: this.contactEmail,
        infoType: this.infoType,
        businessNo: "",
        address: "",
        contactPost: "",
        contactTel: "",
        billingRise: "",
        taxpayerNo: "",
        invoiceTypeId: "",
        specialeNeed: "",
        collectEmail: "",
        point: "",
        serverFee: ""
      };
      let reqReport = reqRep({ traCode: "_ADD_COMPANY", data: reqData });
      requestApiPost(reqReport).then(data => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error"
          });
        } else {
          this.$message({
            message: "注册成功",
            type: "success"
          });
          setTimeout(() => {
            this.$router.push("login");
          }, 1000);
        }
      });
    },
    loginJump() {
      this.$router.push("login");
    },
    selectUser(val) {
      this.infoType = val;
    },
    getCode() {
      if (!this.contactPhone) {
        this.$message.warning("请填写手机号");
        return;
      }
      if (this.btnValue == "获取" || this.btnValue == "重发") {
        this.btnValue = 60;
        var setTime = setInterval(() => {
          if (this.btnValue > 0) {
            this.btnValue--;
          } else {
            this.btnValue = "重发";
            clearInterval(setTime);
          }
        }, 1000);
        this.getCodeRequest();
      }
    },
    //获取短信验证码
    getCodeRequest() {
      if (!base.isPoneAvailable(this.contactPhone)) {
        this.$message.warning("手机号格式不正确");
        return;
      }
      let data = { contactPhone: this.contactPhone };
      base.getAjax("/bizUser/insertAuthCode", data).then(res => {
        if (res.data.code == 1) {
        } else {
          this.$message.error(res.data.message);
        }
      });
    }
  },
  components: {},
  mounted() {
    var dom = document.querySelector(".tip");
    if (window.ActiveXObject != undefined) {
      dom.style.display = "block";
    } else {
      dom.style.display = "none";
    }
  }
};
</script>
<style scoped>
.register {
  min-height: 750px;
  min-width: 600px;
  font-size: 16px;
  overflow-x: auto;
  overflow-y: hidden;
  background-color: #f3f7f9;
}
.register .top-title {
  padding-top: 100px;
  font-size: 50px;
  text-align: center;
  color: #fff;
  display: none;
}
.register .register-box {
  width: 440px;
  margin: 6% auto 0;
  padding: 20px 50px 30px;
  background-color: #fff;
  border-radius: 4px;
  box-sizing: border-box;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.register .register-box .header-switch {
  margin: 0 auto 12px;
  color: #333;
  box-sizing: border-box;
  font-size: 16px;
  border-bottom: 1px solid #deedf0;
}
.header-switch span {
  display: inline-block;
  width: 49%;
  height: 48px;
  line-height: 48px;
  text-align: center;
  cursor: pointer;
}
.active {
  color: #13cb6e;
  border-bottom: 2px solid #13cb6e;
}
.public {
  position: relative;
  width: 100%;
  height: 50px;
  margin-bottom: 12px;
  vertical-align: middle;
}
.getCode {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 60px;
  font-size: 14px;
  text-align: center;
  height: 30px;
  line-height: 30px;
  border-radius: 4px;
  background: #13cb6e;
  color: #fff;
  cursor: pointer;
}
.activeColor {
  background: #ccc;
}
input {
  height: 50px;
  width: 100%;
  padding: 4px 12px 4px 35px;
  box-sizing: border-box;
  outline: none;
  border-radius: 4px;
  background-color: #f7f7f7;
  border: 1px solid rgba(0, 0, 0, 0.04);
}
i {
  position: absolute;
  top: 14px;
  left: 10px;
  width: 18px;
  height: 25px;
  line-height: 25px;
  font-size: 18px;
  color: #969696;
}

.register .sign-in-button {
  line-height: 1.2;
  padding: 12px 20px;
  height: auto;
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  display: block;
  color: #fff;
  background: #13cb6e;
  box-shadow: 0 3px 6px rgba(19, 203, 110, 0.25);
}
.reset-link-box {
  color: #13cb6e;
  margin-top: 20px;
}
.reset-link-box span {
  display: inline-block;
  width: 49%;
  text-align: right;
  cursor: pointer;
}
.forget-password {
  color: #999;
  text-align: left !important;
}
.tip {
  position: relative;
  z-index: 3;
  height: 100%;
  width: 100%;
  background: #fff;
}
.tip .warn {
  margin: 100px auto;
  height: 100px;
  width: 900px;
  font-size: 24px;
  text-align: center;
  color: #fff;
  line-height: 80px;
  background-image: url("../assets/img/bg_tip.jpg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.protocol {
  margin-top: 12px;
}
.protocol .el-checkbox {
  width: auto;
}
.protocol a {
  font-size: 14px;
  cursor: pointer;
  color: #13cb6e;
}
.goback {
  margin-top: 12px;
  padding-top: 12px;
  font-size: 14px;
  border-top: 1px solid #deedf0;
  text-align: left;
  cursor: pointer;
  color: #999;
}
footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  line-height: 60px;
  font-size: 12px;
  text-align: center;
}
footer a {
  color: #999;
}
</style>

